package com.dy.数组.初级._26_从排序数组中删除重复项;


public class Solution {
    public static int removeDuplicates(int[] nums) {
        int return_length = nums.length;

        for(int i =0;i<return_length;i++){
            for(int j=i+1;j<return_length;j++){
                if(nums[i]==nums[j] ){
                    for(int m =j;m<return_length-1;m++){
                        nums[m]=nums[m+1];
                    }
                    j--;
                    return_length--;
                }
            }
        }

        return return_length;
    }

    public static int removeDuplicates2(int[] nums) {
        if (nums.length == 0) return 0;
        int i = 0;
        for(int j=i+1;j<nums.length;j++){
            if(nums[j] !=nums[i]){
                nums[++i] = nums[j];
            }
        }
        return i + 1;
    }

    public static int removeDuplicates3(int[] nums) {
        if (nums.length == 0) return 0;
        int len=0;
        for(int i=len+1;i<nums.length;i++){
            if(nums[i]!=nums[len]){
                len = len+1;
                nums[len] = nums[i];
            }
        }
        return len+1;
    }


}
